package com.lxg.dao;

import com.lxg.pojo.Admin;
import com.lxg.pojo.User;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

/**
 * 有关管理员账号的连接数据库操作，登录验证，注册，修改账号，修改密码
 */

@Mapper
public interface AdminDao {

    /**
     * 根据传入的账号，密码，来查找对应的管理员信息，返回一个Admin类型
     * 用于管理员登录
     *
     * @param username
     * @param password
     * @return
     */
    @Select("select * from admin where username=#{username} and password=#{password} " +
            "and is_deleted = 0")
    public Admin getAdmin(String username, String password);

    /**
     * 获取全部管理员的信息
     *
     * @return
     */
    @Select("select * from admin where is_deleted = 0")
    public ArrayList<Admin> getAllAdmin();

    /**
     * 根据传入的 aid，查找对应管理员
     *
     * @param aid
     * @return
     */
    @Select("select * from admin where aid=#{aid}")
    public Admin getAdminByAid(Integer aid);

    /**
     * 检查该用户名是否已经被占用
     * @param username
     * @return
     */
    @Select("select * from admin where username=#{username}")
    public Admin checkUsername(String username);

    /**
     * 管理员根据aid删除普通管理员
     *
     * @param aid
     */
    @Update("update admin set is_deleted = 1 where aid=#{aid}")
    public void deleteAdminByAid(Integer aid);

    /**
     * 超级管理员添加一个普通管理员
     *
     */
    @Insert("insert into admin (username,password) values " +
            "(#{username},#{password})")
    public void addAdmin(String username , String password);


    @Select("select  count(*) from admin where isSuper = 1")
    Integer getSuperAdminNum();

    @Select("select  count(*) from admin where isSuper = 0")
    Integer getAdminNum();

    @Select("select * from admin where  is_deleted = 0 and username like CONCAT('%',#{username},'%')")
    public ArrayList<Admin> getAllLikeAdminByUsername(String username);


    @Update("update admin set username=#{username},password=#{password} where aid=#{aid}")
    void updateAdmin(String username, String password, Integer aid);
}
